﻿


$.MGJ.ReturnProduct = [];

(function () {
    var _this = $.MGJ.ReturnProduct;
    $.extend($.MGJ.ReturnProduct, {
        // 显示详细数据
        Dialog_ShowDataObj: null,
        Dialog_ShowData: function (obj) {
            var id = $(obj).attr("ID");
            this.Dialog_ShowDataObj = $.L.dialog({
                url: ACTION_URL("ReturnProData", "FleeGoods") + "?id=" + id,
                title: "详细数据",
                width: 1100,
                height: 'auto',
                buttons: {
                    "button_cancel": {
                        type: 'primary',
                        text: '返回',
                        click: 'MODALMISS'
                    }
                },
            });
        },

        // 申请退货
        Dialog_CodeInfoObj: null,
        Dialog_CodeInfo: function () {
            this.Dialog_CodeInfoObj = $.L.dialog({
                url: ACTION_URL("CodeInfo", "FleeGoods"),
                title: "输入物流码信息",
                width: 800,
                height: 'auto',

            });
        },

        // 编辑退货信息
        Dialog_EditReturnObj: null,
        Dialog_EditReturn: function (obj) {
            var TheText;
            var index_1 = $("#tableList_right tr").index($(obj).parent().parent());
            $("#tableList tr").each(function () {
                var index_2 = $(this).index();
                if (index_2 == index_1) {
                    TheText = $(this).find(".CheckText").text();
                }
            })
            var id = $(obj).attr("ID");
            if (TheText == "等待提交" || TheText == undefined) {
                this.Dialog_EditReturnObj = $.L.dialog({
                    url: ACTION_URL("EditReturn", "FleeGoods") + "?id=" + id,
                    title: "编辑退货信息",
                    width: 800,
                    height: 'auto',
                    buttons: {
                        "button_save": {
                            type: 'primary',
                            text: '确认提交',
                            click: function () {
                                if ($("#ProductName").val() != "") {
                                    _this.Ajax_SaveDate();
                                } else {
                                    $.L.msgError("产品名称不能为空")
                                }
                            }
                        },
                        "button_cancel": {
                            type: 'default',
                            text: '取消',
                            click: function () {
                                $.MGJ.ReturnProduct.Dialog_EditReturnObj.close();
                                $.MGJ.ReturnProduct.Ajax_SearchPageList(1);
                            }
                        },
                    },
                });
            } else {
                this.Dialog_EditReturnObj = $.L.dialog({
                    url: ACTION_URL("EditReturn", "FleeGoods") + "?id=" + id,
                    title: "编辑退货信息",
                    width: 800,
                    height: 'auto',
                    buttons: {
                        "button_cancel": {
                            type: 'default',
                            text: '取消',
                            click: function () {
                                $.MGJ.ReturnProduct.Dialog_EditReturnObj.close();
                                $.MGJ.ReturnProduct.Ajax_SearchPageList(1);
                            }
                        },
                    },
                });
            }
        },

    });
})(jQuery);
(function () {
    var _index = 1;
    var _this = $.MGJ.ReturnProduct;
    $.extend($.MGJ.ReturnProduct, {

        //分页查询
        Ajax_ReturnPageList: function (pageIndex) {
            _index = pageIndex;
            var key = $("#Key").val();

            $.L.ajaxHandle({
                url: ACTION_URL("ProReturnPageList", "FleeGoods"),
                data: {
                    key: key,
                    pageIndex: pageIndex,
                    pageSize: 10

                },
                success: function (response) {
                 
                    $("#tableList").L_bindingDataList(response);
                    $("#tableList_left").L_bindingDataList(response);
                    $("#tableList_right").L_bindingDataList(response);


                    //if ($(obj).parent().siblings(".CheckText").text() == "等待审核" || $(obj).text()=="") {


                }
            });
        },
        //多条件查询
        Ajax_SearchPageList: function (pageIndex) {
            _index = pageIndex;
            window.SearchKey = removeSpace($("#Key").val());
            $.L.ajaxHandle({
                url: ACTION_URL("SearchPageList", "FleeGoods") + "?pageindex=" + pageIndex,
                data: $("#SearchForm").serialize(),
                success: function (response) {
                    $("#tableList").L_bindingDataList(response);
                    $("#tableList_left").L_bindingDataList(response);
                    $("#tableList_right").L_bindingDataList(response);
                    for (var i = 0; i < response.PageData.length; i++) {
                        var TheText = response.PageData[i].CheckText
                        if (TheText != "等待提交" || TheText == "") {
                            //$("#tableList_right tr").eq(i).find("td a:first-child").text("查看");
                            $("#tableList_right tr").eq(i).find("td a:first-child").attr("style", "visibility:hidden;")
                        }
                        if (TheText != "等待提交" && TheText != "正在审核") {
                            $("#tableList_right tr").eq(i).find('.IfTextBtn').css('color', '#DEDEDE').removeAttr('onclick').attr('title', '点击无效');
                        }

                    }
                }
            });
        },
        //填写物流码
        Ajax_LittleProReturn: function () {
            var BoxCodes = $("#BoxCodes").val();
            $.L.ajaxHandle({
                url: ACTION_URL("ProReturnLittleCode", "FleeGoods"),
                data: {
                    BoxCode: BoxCodes,
                },
                success: function (response) {
                    data = eval('(' + response + ')');
                    //跳转到编辑页面
                    if (data.id > 0) {
                        _this.Dialog_CodeInfoObj.close();
                        $.MGJ.ReturnProduct.Dialog_EditReturn({ 'ID': data.id });
                    } else {
                        $.L.msgError(data.text);
                    }
                }
            });
        },
        //编辑
        Ajax_SaveDate: function () {
            $.L.ajaxHandle({
                url: ACTION_URL("ProReturnSaveDate", "FleeGoods"),
                data: $("#form").serialize(),
                success: function (r) {
                    if (r <= 0) $.L.msgSuccess("提交失败！");
                    else {
                        $.L.msgSuccess("提交成功！");
                        _this.Dialog_EditReturnObj.close();
                        _this.Ajax_SearchPageList(1);
                    }

                }
            });
        },
        //删除
        Ajax_Del: function (obj) {
            var index = $(obj).parent().parent().index();
            var stutas=$('#tableList tr').eq(index).find('.CheckText').text();
            if (stutas == "等待提交") {
                $.L.msgConfirm("确认删除该记录?", function () {
                    var ID = $(obj).attr("ID");
                    $.L.ajaxHandle({
                        url: ACTION_URL("ProReturnDel", "FleeGoods"),
                        data: {
                            id: ID,
                        },
                        success: function (r) {
                            if (r > 0) {
                                $.L.msgSuccess("删除成功！");
                                _this.Ajax_SearchPageList(_index);
                            }
                        }
                    });
                })
            } else {
                $.L.msgError("申请已提交，无法删除");
            }
           

        },
        //取消
        Ajax_Cansole: function (obj) {
            var FormCode = $(obj).attr("FormCode");
            var FilePath = $(obj).attr("FilePath");
            var index = $(obj).parent().parent().index();
            var stutas=$('#tableList tr').eq(index).find('.CheckText').text();
            if (stutas == "等待提交" || stutas == "正在审核") {
                $.L.ajaxHandle({
                    url: ACTION_URL("ProCansole", "FleeGoods"),
                    data: {
                        formCode: FormCode,
                        filePath: FilePath
                    },
                    success: function (res) {
                        $.L.msgSuccess(res);
                            _this.Ajax_SearchPageList(_index);
                  
                    }
                })
            }
        }
    });
})(jQuery);
(function () {
    var _this = $.MGJ.ReturnProduct;
    $.extend($.MGJ.ReturnProduct, {


    });
})(jQuery);

